package com.cgbl.service.pop

import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import com.cgbl.service.R
import com.cgbl.service.adapter.FilterAdapter
import com.lxj.xpopup.impl.PartShadowPopupView

class ProjectFilterPop(
    context: Context,
    val select: String,
    val list: ArrayList<String>
) :
    PartShadowPopupView(context) {
    private var confirmClickListener: (id: String) -> Unit = {}
    private lateinit var recyclerView: RecyclerView
    private lateinit var selectCourseAdapter: FilterAdapter
    override fun getImplLayoutId(): Int {
        return R.layout.app_pop_project_filter
    }

    override fun initPopupContent() {
        super.initPopupContent()

        recyclerView = findViewById(R.id.recyclerView)
        selectCourseAdapter = FilterAdapter(select)
        recyclerView.adapter = selectCourseAdapter
        selectCourseAdapter.setOnItemClickListener { adapter, view, position ->
            confirmClickListener.invoke(selectCourseAdapter.data[position])
        }
        selectCourseAdapter.setNewInstance(list)
    }


    fun setConfirmClickListener(click: (id: String) -> Unit): ProjectFilterPop {
        confirmClickListener = click
        return this
    }
}